LISTING #1 - makePolyButton script
--message makePolyButton
--syntax: makePolyButton(inMessage,outMessage)
----------inMessage is message to be called by 
-----------------clicks within the polyButton
----------outMessage is message to be called by 
-----------------clicks outside the polyButton

on makePolyButton inMessage,outMessage
	put empty into pointList
	choose line tool
	set the cursor to cross
	wait until the mouseClick
	put the clickLoc into pointList

	repeat
		wait until the mouseClick
		put return & the clickLoc after pointList
		put the number of lines of pointListÂ
		into count
		drag from (line count-1 of pointList)Â
		to (line count of pointList)
		if abs(item 1 of last line of pointListÂ
		- item 1 of first line of pointList)<2Â
		and abs(item 2 of last line of pointListÂ
		- item 2 of first line of pointList)<2Â
		then exit repeat
	end repeat

	put line 1 of pointList intoÂ
	last line of pointList
	put the number of card buttons into cbCount
	set lockScreen to true
	doMenu revert
	choose button tool

	put item 1 of line 1 of pointList into maxV
	put item 1 of line 2 of pointList into maxPenV
	put item 1 of line 1 of pointList into minV
	put item 1 of line 2 of pointList into minPenV

	put item 2 of line 1 of pointList into maxH
	put item 2 of line 2 of pointList into maxPenH
	put item 2 of line 1 of pointList into minH
	put item 2 of line 2 of pointList into minPenH

	repeat with i=2 to count

		get item 1 of line i of pointList
		if it > maxPenV then	--find the largest
			if it > maxV then 	--and second largest v
				put maxV into maxPenV
				put it into maxV
			else
				put it into maxPenV
			end if
		end if

		if it < minPenV then 	--find the smallest
			if it < minV then	--and second smallest v
				put minV into minPenV
				put it into minV
			else
				put it into minPenV
			end if
		end if

		get item 2 of line i of pointList
		if it > maxPenH then	--find the largest
			if it > maxH then	--and second largest h
				put maxH into maxPenH
				put it into maxH
			else
				put it into maxPenH
			end if
		end if

		if it < minPenH then	--find the smallest
			if it < minH then	--and second smallest h
				put minH into minPenH
				put it into minH
			else
				put it into minPenH
			end if
		end if

	end repeat

	add 1 to cbCount	--create the interior button
	doMenu "new button"
	set the style of card button cbCountÂ
	to transparent
	set the showName of card button cbCountÂ
	to false
	set the autoHilite of card button cbCountÂ
	to false
	set the rect of card button cbCountÂ
	to minPenV,minPenH,maxPenV,maxPenH
	put "on mouseUp" into theScript
	put return & inMessage after theScript
	put return & "end mouseUp" after theScript
	set the script of card button cbCountÂ
	to theScript

	repeat with i=1 to count-1
		add 1 to cbCount	--create the edge buttons
		set the cursor to busy
		put line i of pointList into firstPoint
		put line (i+1) of pointList into secondPoint
		doMenu "new button"
		set the name of card button cbCountÂ
		to "split" && i

		--determine the cošrdinates of the button:

		if (item 1 of firstPoint) < (item 1Â
		of secondPoint) then
			put item 1 of firstPoint into top
			put item 1 of secondPoint into bottom
		else
			put item 1 of secondPoint into top
			put item 1 of firstPoint into bottom
		end if
		if (item 2 of firstPoint) > (item 2Â
		of secondPoint) then
			put item 2 of firstPoint into right
			put item 2 of secondPoint into left
		else
			put item 2 of secondPoint into right
			put item 2 of firstPoint into left
		end if

		set the rect of card button cbCountÂ
		to top,left,bottom,right
		set the style of card button cbCountÂ
		to transparent
		set the showName of card button cbCountÂ
		to false
		set the autoHilite of card button cbCountÂ
		to false

		--determine the orientation of the
		--"split" of the button:

		put "on mouseUp" into theScript

		if (item 1 of firstPoint) > (item 1Â
		of secondPoint) then
			if (item 2 of firstPoint) > (item 2Â
			of secondPoint) then
				put return & "split " & quote & "\"Â
				& quote & "," & inMessage & "," &Â
				outMessage after theScript
			else
				put return & "split " & quote & "/"Â
				& quote & "," & inMessage & "," &Â
				outMessage after theScript
			end if
		else
			if (item 2 of firstPoint) > (item 2Â
			of secondPoint) then
				put return & "split " & quote & "/"Â
				& quote & "," & outMessage & "," &Â
				inMessage after theScript
			else
				put return & "split " & quote & "\"Â
				& quote & "," & outMessage & "," &Â
				inMessage after theScript
			end if
		end if

		put return & "end mouseUp" after theScript

		set the script of card button cbCountÂ
		to theScript
	end repeat

	choose browse tool
end makePolyButton
